package com.fourpigeon.config;

import com.fourpigeon.utils.AddResponseHeaderFilter;
import com.fourpigeon.utils.LoginInterceptor;
import com.fourpigeon.utils.RefreshUserTokenInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
public class SpringMvcConfig implements WebMvcConfigurer{
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    /**
     * 添加拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new RefreshUserTokenInterceptor(stringRedisTemplate))
                .excludePathPatterns(
                        "/user/login/wechat"
                )
                .order(0);
        registry.addInterceptor(new LoginInterceptor(stringRedisTemplate))
                //设置放行路径
                .excludePathPatterns(
                        "/user/login/wechat",
                        //分页查询组
                        "/blog/**/page/**",
                        //搜索
                        "/blog/SearchDailies/**",
                        "/blog/SearchDeals/**",
                        "/blog/SearchPractices/**",
                        "/blog/SearchAgrees/**",
                        //热门
                        "/blog/hotBlog/{blogType}",
                        //评论
                        "/blog/comment/get/**",
                        //单个
                        "/blog/daily/{blogId}",
                        "/blog/deal/{blogId}",
                        "/blog/agreement/{blogType}/{blogId}",
                        "/blog/practice/{blogId}",
                        //点击量
                        "/click/{blogType}/{blogId}"
                ).order(1);
    }
}
